﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Security;
using KYO.DAL;
using ObjectPersistence;

public partial class Setup : System.Web.UI.Page
{
    ModuleAssembler moduleService = new ModuleAssembler();
    protected void Page_Load(object sender, EventArgs e)
    {
        GridView1.DataSource = moduleService.ReadCollectionAll();
        GridView1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataSet ds = ReadConfig();

        DataTable table = ds.Tables["module"];
        DataRow row = table.Rows[0];
        //Response.Write(row["modulePath"]);
        //Response.Write(row["fileName_Text"]);

        Module module = new Module();
        module.Author = row["author"].ToString();
        module.CopyRight = row["copyRight"].ToString();
        module.Description = row["description"].ToString();
        module.Name = row["name"].ToString();
        module.Version = row["version"].ToString();

       table = ds.Tables["filename"];
       row = table.Rows[0];
       module.ModulePath = row["modulePath"].ToString();
       module.FileName = row["filename_Text"].ToString();
      // moduleService.MakePersistent(module, true);

   
        
    }

    public string ModuleConfigFile
    {
        get
        {

            return Server.MapPath("Modules") + @"\SampleModule\ModuleConfig.config";
        }
    }
    public DataSet ReadConfig()
    {
        DataSet ds = null;
        try
        {
            if (System.IO.File.Exists(ModuleConfigFile))
            {
                ds = new DataSet();
               
                ds.ReadXml(ModuleConfigFile);
            }
        }
        catch (SecurityException e)
        {
            // Do not throw exceptions
          
            return null;
        }

       
        return ds;
    }
}
